package tw.com.softleader.reins.demo.book.app;
 
import tw.com.softleader.reins.demo.book.entity.Book;
import tw.com.softleader.reins.demo.book.service.BookService;

public class BookApp {
	public static void main(String[] args){
		System.out.printf("%-8s%-15s%-15s%-25s%-15s%n", 
				"[ID]", "[Title]", "[Writer]", "[ISBN]", "[Publication]");
		BookService bookService = new BookService();
		for (Book book:bookService.getAll()) {
			System.out.printf(" %-7s%-15s%-15s%-25s%-15s%n", 
					book.getId(), book.getTitle(), book.getWriter(), book.getIsbn(), book.getPublication());
		}
		
		System.out.println();
		
		int bookId = 2;
		Book book = bookService.getById(bookId);
		try {
			System.out.printf(" %-7s%-15s%-15s%-25s%-15s%n", book.getId(), book.getTitle(), book.getWriter(), book.getIsbn(), book.getPublication());
		} catch (NullPointerException e) {
			// TODO Auto-generated catch block
			System.out.println("沒有ID為["+bookId+"]的資料");
		}

	}
}
